import * as echarts from "echarts";
import { markRaw } from "vue";
import { EChartsOption } from "echarts/types/dist/shared";
export default class ZZEcharts {
	public option = {};
	public echartsEntity = ref();
	static doms: HTMLElement | null;
	constructor(option: EChartsOption, dom: HTMLElement) {
		this.echartsEntity.value = markRaw(echarts.init(reactive(dom)));
		this.option = JSON.parse(JSON.stringify(option));
		if (this.option && typeof this.option === "object") {
			this.echartsEntity.value.setOption(this.option);
		}
	}
	public echartsClick = () => {
		this.echartsEntity.value.on("click", (params: any) => {
			this.echartsEntity.value.setOption({
				series: [
					{
						markPoint: {
							data: [
								{
									name: "当前节点",
									value: params.data,
									coord: [params.dataIndex, params.data]
								}
							]
						}
					}
				]
			});
		});
	};
	public setOption = (option: any) => {
		this.echartsEntity.value.setOption(option);
	};
}
